package me.yricky.cov_spectrum.model.utils

import io.ktor.http.*
import me.yricky.cov_spectrum.model.ApiConstant
import me.yricky.cov_spectrum.model.beans.QueryCase

val QueryCase.webPageUrl get() = URLBuilder().apply {
    takeFrom("https://cov-spectrum.org/explore/World/AllSamples/Past6M/variants")
    parameters.apply {

        nextcladePangoLineage?.let { append(ApiConstant.PK_NEXT_CLADE, it) }
        variantQuery?.let { append(ApiConstant.PK_VARIANT_QUERY, it) }
        pangoLineage?.let { append(ApiConstant.PK_PANGO, it) }

        aaMutations.takeIf { it.isNotEmpty() }?.let {
            append(ApiConstant.PK_AA_M, it.reduce { s1, s2 -> "$s1,$s2" })
        }
        nucMutations.takeIf { it.isNotEmpty() }?.let {
            append(ApiConstant.PK_NUC_M, it.reduce { s1, s2 -> "$s1,$s2" })
        }
        aaInsertions.takeIf { it.isNotEmpty() }?.let {
            append(ApiConstant.PK_AA_I, it.reduce { s1, s2 -> "$s1,$s2" })
        }
        nucInsertions.takeIf { it.isNotEmpty() }?.let {
            append(ApiConstant.PK_NUC_I, it.reduce { s1, s2 -> "$s1,$s2" })
        }
    }
}.build()